package com.cloudlead.dictionaryAction.action;
import com.cloudlead.common.lang.annotation.Label;
import com.cloudlead.common.lang.persistence.EasyuiGridData;
import com.cloudlead.common.lang.persistence.OnlineUser;
import com.cloudlead.common.lang.persistence.Page;
import com.cloudlead.common.worker.action.impl.AbstractActionFactory;
import com.cloudlead.common.worker.annotation.Action;
import com.cloudlead.common.worker.annotation.Order;
import com.cloudlead.commonData.vo.BaseDock;
import com.cloudlead.commonData.vo.BasePort;
import com.cloudlead.dictionaryAction.BusinessModules;
import com.cloudlead.dictionaryAction.service.ManagementSer;
import com.cloudlead.dictionaryAction.service.WechatlogEditSer;
import com.cloudlead.dictionaryService.ManagementService;
import com.cloudlead.dictionaryService.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2015/10/28.
 */
@Controller
public class ManagementAcitonFactory extends AbstractActionFactory implements ManagementService {
    public ManagementAcitonFactory() {
        super(BusinessModules.Management);
    }
    @Autowired
    ManagementSer managementSer;

    @Autowired
    WechatlogEditSer wechatlogEditSer;
    @Override
    @Action
    @Order(1)
    @Label("待审核公司列表")
    public EasyuiGridData companyList(RegCompanyVo regCompanyVo,@Label("每页条数")int rows,@Label("页码")int page) {
        return new EasyuiGridData(managementSer.companyList(regCompanyVo,rows,page),
                "isAdmin,baseCompany.id id,baseCompany.status status,baseCompany.companyName companyName,baseCompany.identity identity," +
                        "baseCompany.companyType companyType,baseCompany.companyLevel companyLevel,baseCompany.carsCount carsCount" +
                        ",baseCompany.shipsCount shipsCount,baseCompany.dangerous dangerous," +
                        "baseCompany.companyPhone1 companyPhone1,baseCompany.companyPhone2 companyPhone2,baseCompany.companyAddress companyAddress," +
                        "baseCompany.comments comments,baseCompany.bank bank," +
                        "baseCompany.businessLicense businessLicense,baseCompany.taxRegistrationFilePath taxRegistrationFilePath," +
                        "baseCompany.logoImage logoImage");
    }

    @Override
    @Action
    @Order(2)
    @Label("根据公司ID查询信息")
    public Object companyInfo(@Label("公司ID")@NotNull String id) {
        return managementSer.companyInfo(id);
    }

    @Override
    @Action
    @Order(3)
    @Label("审核公司")
    public Object audit(@Label("公司ID")@NotNull String companyId) {
        return managementSer.audit(companyId);
    }

    @Override
    @Action
    @Order(4)
    @Label("航线类别查询")
    public EasyuiGridData shipRouteList(BaseVoyageVo baseVoyageVo,@Label("每页条数")int rows,@Label("页码")int page) {
        return new EasyuiGridData(managementSer.voyageList(baseVoyageVo, rows, page),"id");
    }

    @Override
    @Action
    @Order(5)
    @Label("日志查询")
    public EasyuiGridData logList(@Label("日志") TbLogVo tbLogVo,@Label("每页条数") int rows,@Label("页码") int page) {
        return new EasyuiGridData(managementSer.tbLogList(tbLogVo, rows, page),"id,operator,operationContent,operationTime");
    }

    @Override
    @Action
    @Order(6)
    @Label("导入日志查询")
    public EasyuiGridData importLog(@Label("导入日志")TbImportLogVo tbImportLogVo,@Label("每页条数") int rows,@Label("页码") int page) {
        return new EasyuiGridData(managementSer.importLog(tbImportLogVo, rows, page),"id,bussinessCode,error,fileName," +
                "importResult,importTime,location");
    }

    @Override
    @Action
    @Order(7)
    @Label("发送记录查询")
    public EasyuiGridData mailLog(@Label("发送记录")TbMailLogVo tbMailLogVo,@Label("每页条数") int rows,@Label("页码") int page) {
        return new EasyuiGridData(managementSer.mailLog(tbMailLogVo, rows, page),"id,fileName,mailContent,mailTime,mailTo");
    }

    @Override
    @Action
    @Order(8)
    @Label("查询微信日志")
    public EasyuiGridData WechatloglList(@Label("微信日志")WechatlogVo wechatlogVo, @Label("每页条数")int rows, @Label("页码")int page) {
        return new EasyuiGridData(wechatlogEditSer.WechatlogList(wechatlogVo, rows, page),"id,driverName,containerNo,tel,nowTime,active");
    }

    @Override
    @Action
    @Order(9)
    @Label("删除公司")
    public void delCompany(@Label("公司ID") @NotNull String companyId) {
        managementSer.delCompany(companyId);
    }

    @Override
    @Action
    @Order(10)
    @Label("码头查询")
    public EasyuiGridData baseDock(@Label("码头查询")BaseDockVo baseDockVo,@Label("每页条数") int rows,@Label("页码") int page) {
        return new EasyuiGridData(managementSer.baseDock(baseDockVo, rows, page),"id,name,code,comments,portName,location");
    }

    @Override
    @Action
    @Order(10)
    @Label("门点查询")
    public EasyuiGridData baseDoor(@Label("门点查询")BaseDoorVo baseDoorVo,@Label("每页条数") int rows,@Label("页码") int page) {
        return new EasyuiGridData(managementSer.baseDoor(baseDoorVo, rows, page),"id,name,comments,basePlace.name location,basePlace.id basePlaceId");
    }

    @Override
    @Action
    @Order(9)
    @Label("删除码头")
    public void delDock(@Label("码头ID") @NotNull String id) {
        managementSer.delDock(id);
    }

    @Action
    @Order(10)
    @Label("查询在线用户列表")
    public EasyuiGridData findOnlineUser(){
        List rows= OnlineUser.getInstance().getList();
        EasyuiGridData data= new EasyuiGridData();
        data.setRows(rows);
        List foot=new ArrayList<>();
        HashMap map=new HashMap();
        map.put("onlineTime",rows.size());
        map.put("userName","合计");
        foot.add(map);
        data.setFooter(foot);
        return data;
    }

    @Action
    @Order(11)
    @Label("航线查询")
    public EasyuiGridData baseShipRoute(BaseShipRouteVo vo,int rows,int page){
        return new EasyuiGridData(managementSer.baseShipRoute(vo, rows, page),"id,startCity,endCity,startPort,destPort,status,comments,flag");
    }

    @Action
    @Order(12)
    @Label("航线删除")
    public void delShipRoute(String id){
        managementSer.delShipRoute(id);
    }

    @Action
    @Order(13)
    @Label("航线增加")
    public String createShipRoute(BaseShipRouteVo vo){
        return managementSer.createShipRoute(vo);
    }

    @Action
    @Order(14)
    @Label("航线修改")
    public String editShipRoute(BaseShipRouteVo vo){
        return managementSer.editShipRoute(vo);
    }

    @Action
    @Order(15)
    @Label("港口多值查询")
    public List<BasePortVo> findAllPort(@NotNull @Label("港口查询") BasePortVo vo) {
        return managementSer.findAllPort(vo);
    }
    @Action
    @Order(20)
    @Label("港口单值查询")
    public List findOnePort(BasePortVo vo){
        return managementSer.findOnePort(vo);
    }

    @Action
    @Order(16)
    @Label("港口分页显示")
    public EasyuiGridData basePort(BasePortVo vo,int rows,int page){
        return new EasyuiGridData(managementSer.basePort(vo, rows, page),"id,portName,portCode,city.name name,city.id cityId");
    }
    @Action
    @Order(17)
    @Label("港口增加")
    public String createPort(BasePortVo vo){
       return managementSer.createPort(vo);
    }
    @Action
    @Order(18)
    @Label("港口编辑")
    public String editPort(BasePortVo vo){
        return managementSer.editPort(vo);
    }
    @Action
    @Order(19)
    @Label("港口删除")
    public void delBasePort(String id){
        managementSer.delBasePort(id);
    }
}